package cn.wolfcode.edu.service.impl;

import cn.wolfcode.edu.domain.Classroom;
import cn.wolfcode.edu.mapper.ClassroomMapper;
import cn.wolfcode.edu.query.QueryObject;
import cn.wolfcode.edu.service.IClassroomService;
import cn.wolfcode.edu.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by ASUS on 2018/7/8.
 */
@Service
public class ClassroomServiceImpl implements IClassroomService {

    @Autowired
    private ClassroomMapper classroomMapper;

    @Override
    public PageResult query(QueryObject qo) {

        List<Classroom> list=classroomMapper.queryForList(qo);
        int total= classroomMapper.queryForRows();
        return new PageResult(total,list);
    }

    /**
     *
     * @param classroom 要保存的教室对象
     */
    @Override
    public void insertClassroom(Classroom classroom) {
       classroomMapper.insert(classroom);
    }

    @Override
    public void updateClassroom(Classroom classroom) {
        classroomMapper.updateByPrimaryKey(classroom);
    }

    @Override
    public List<Classroom> selectAllClassroom() {

        List<Classroom> classrooms = classroomMapper.selectAll();
        return classrooms;
    }

    public Classroom getByName(String name) {
        return classroomMapper.getByName(name);
    }

    @Override
    public List<Classroom> listAllClassroomExStatus() {
        List<Classroom> classrooms = classroomMapper.listAllClassroomExStatus();
        return classrooms;
    }

    @Override
    public void enableClassroom(Long id, Long statusNum) {
        classroomMapper.enableClassroom(id,statusNum);
    }
}
